﻿using ControlCore.Controller;
using System;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;

/// REMARKS:
/// 
// VoiceCommandDisplayName = Properties.Resources.KinectReady;
// set up kinect audio
// var commandList = new List<AudioCommand>();
// commandList.Add(new AudioCommand("Stop", "stop"));
// _kinectAudio = new KinectAudio(KinectManager.KinectSensor, commandList);
// _kinectAudio._newCommand += _kinectAudio__newCommand;
// VoiceCommandDisplayName = Properties.Resources.KinectNotDetected;   
/// 

namespace KinectController
{
    [Export(typeof(IController))]
    [ExportMetadata("Name", "Kinect controller")]
    public class KinectController : IController
    {
        public event EventHandler<ControllerCommandEventArgs> CommandReceived;

        private KinectVision kinectVision;
        private KinectAudio kinectAudio;

        private FrameworkElement controllerOutput;
        public FrameworkElement ControllerOutput
        {
            get
            {
                if (kinectVision != null)
                {
                    //// _controllerOutput = new Image() { Source = _kinectVision.RenderedImage };
                    this.controllerOutput = this.kinectVision.OutputControl;
                    return controllerOutput;
                }

                return null;
            }
        }

        public bool IsInitialized { get; private set; }

        public void Init()
        {
            // Initialize kinect device
            if (KinectManager.Start())
            {
                // set up kinect vision
                this.kinectVision = new KinectVision(KinectManager.KinectSensor);
                var mainImage = this.kinectVision.ColorBitmap;
                // _kinectVision.RenderedImage;
                this.IsInitialized = true;
            }

            this.IsInitialized = false;
        }

        public void Close()
        {
            this.IsInitialized = false;
        }
    }
}
